#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int mod=998244353,inf=0x3f3f3f3f3f3f3f3f;
const int N=1.2e3+10,M=2e5+10;
mt19937 rnd(time(0));
int vf[N],fa[N],dep[N];
int n;
vector<int>e[N],leaf[N];
map<pair<int,int>,int>f[N];
void dfs1(int x)
{
	dep[x]=dep[fa]+vf[x];
	if(e[x].empty())leaf[x].push_back(x);
	for ( auto v:e[x] )
	{
		dfs1(v);
		for ( auto w:leaf[v] )leaf[x].push_back(w);
	}
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
//	freopen("trip.in","r",stdin);
//	freopen("trip.out","w",stdout);
	cin >> n;
	for ( int i = 2 ; i <= n ; i++ )
	{
		cin >> fa[i] >>vf[i];
		e[fa[i]].push_back(i);
	}
	dfs1(1);
	return 0;
}


